<template>
  <div>
    <div>
      <el-form
        :inline="true"
        :rules="rules"
        ref="ruleForm"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="护士名称" prop="name">
          <el-input
            v-model="formInline.name"
            placeholder="请输入查询名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="护士科室" prop="department">
          <el-input
            v-model="formInline.department"
            placeholder="请输入科室"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="tabol">
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="name" label="医生姓名" width="180">
        </el-table-column>
        <el-table-column prop="department" label="所属科室" width="180">
        </el-table-column>
        <el-table-column prop="address" label="医生头像" width="180">
          <!-- slot-scope="scope" -->
          <template slot-scope="scope">
            <div class="block">
              <el-avatar
                shape="square"
                :size="80"
                :src="scope.row.head"
              ></el-avatar>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="联系方式" width="180">
        </el-table-column>
        <el-table-column prop="sex" label="性别" width="180"> </el-table-column>
      </el-table>
    </div>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[5, 10, 20, 30]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pages.total"
    >
    </el-pagination>
   
  </div>
</template>

<script>
import { api_doctor_search_doctor,api_doctor_list_doctor } from "@/apis/doctor";
export default {
  data() {
    return {
      formInline: {
        name: "",
        department: "",
       
      },
      currentPage4: 4,
      rules: {
        name: [{ required: true, message: "请输入查询名称", trigger: "blur" }],
        department: [
          { required: true, message: "请输入科室", trigger: "change" },
        ],
      },
      pages: {
        page: 1,
        size: 10,
        total:10
      },
      tableData: [],
    };
  },
  created() {
    this.getList();
  },

  methods: {
    async getList() {
      let res = await api_doctor_list_doctor(this.pages);
      console.log(res);
      if (res.data.code == 1) {
      
          this.tableData = res.data.data;
          this.pages.total=res.data.total
         
        }
      
    },
    // 模糊查询
    async getUsrList() {
      let res = await api_doctor_search_doctor({...this.pages,...this.formInline});
      console.log(res);
      if (res.data.code == 1) {
      
          this.tableData = res.data.data;
          this.pages.total=res.data.total
         
        }
      
    },
    onSubmit() {
      console.log("submit!");
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.getUsrList()
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleSizeChange(val) {
      this.pages.size=val
      this.getList()
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.pages.page=val
      // console.log(`当前页: ${val}`);
      this.getList()
    },
  },
};
</script>

<style lang="less" scoped>
.tabol {
  border: 1px solid #ccc;

  /deep/.el-avatar--square {
    border-radius: 20px;
  }
}
</style>